<template>
    <div id="login">
        <el-tabs v-model="activeName" @tab-click="handleClick">
            <el-tab-pane label="修改信息" name="basic">
            <el-form ref="formSystem" :model="formSystem" label-width="120px">

            <el-form-item label="账号">
            <el-input ref="name" v-model="formSystem.username" placeholder="请输入账号"></el-input>
            </el-form-item>
            <el-form-item label="密码">
            <el-input ref="name" v-model="formSystem.password" placeholder="请输入密码"></el-input>
            </el-form-item>

            <el-form-item>
            <el-button type="success" icon="el-icon-check" @click="submitSystem">修改</el-button>
            </el-form-item>
            </el-form>
            </el-tab-pane>
            </el-tabs>
    </div>


</template>

<script>
    import {
        post
    } from '@/network/request'
    import {
        __URL__
    } from '@/main'

    export default {
        name: 'Login',
        data() {
            return {
                captcha: __URL__ + '/captcha?random=' + Math.random(), // 验证码地址
                form: {
                    username: '',
                    password: '',
                    captcha: ''
                }
            }
        },
        methods: {
            // 更换验证码
            captchaChange() {
                this.captcha = __URL__ + '/captcha?random=' + Math.random()
            },
            // 登录
            login() {
                if (this.form.username == '') {
                    this.$notify.info({
                        title: '系统提示',
                        message: '请输入管理员账号',
                        offset: 70
                    })
                    this.$refs['username'].focus()
                    return false
                }
                if (this.form.password == '') {
                    this.$notify.info({
                        title: '系统提示',
                        message: '请输入管理员密码',
                        offset: 70
                    })
                    this.$refs['password'].focus()
                    return false
                }
                post('/login', this.form).then(res => {
                    const result = res.data
                    if (result.code == 200) {
                        sessionStorage.setItem('token', result.data.token)
                        sessionStorage.setItem('cid', result.data.cid)
                        sessionStorage.setItem('nickname', result.data.nickname)
                        sessionStorage.setItem('main', result.data.main)
                        this.$router.push('/user')
                    } else {
                        this.captcha = __URL__ + '/captcha?random=' + Math.random()
                        this.form.username = ''
                        this.form.password = ''
                        this.form.captcha = ''

                        this.$notify.error({
                            title: '系统提示',
                            message: result.message,
                            offset: 70
                        })
                    }
                }).catch()
            }
        }
    }
</script>

<style>
</style>